name: Run Sonar

on: 
  schedule:
    - cron: '30 15 * * SAT'
  workflow_dispatch:

jobs:
  sonar:
    runs-on: [ubuntu-latest]
    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
    - name: Setup JDK 11
      uses: actions/setup-java@v1
      with:
        java-version: 11
    - name: Gradle Cache
      uses: actions/cache@v2
      with:
        path: |
          ~/.gradle/caches
          ~/.gradle/wrapper
        key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
        restore-keys: |
          ${{ runner.os }}-gradle-
    - name: Gradle Test & Coverage Report
      run: ./gradlew test jacocoTestReport -Dorg.gradle.jvmargs=-Xmx4096m
    - name: Sonarcloud Scan
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        SONAR_TOKEN: ${{ secrets.ZAPBOT_SONARCLOUD_TOKEN }}
      run: ./gradlew -Dorg.gradle.jvmargs=-Xmx4g sonarqube --stacktrace
